$(function () {

    getCompanyFindById();
})

function getCompanyFindById() {

    let id = sessionStorage.getItem("companyId");
    console.log(id);
    $.ajax({
        url: '/CompanyFindById',
        data: {id: id},
        type: 'get',
        dataType: 'json',
        success: function (data) {
            setCompanyFindById(data[0].object);
        }
    })
    sessionStorage.setItem("companyId", null);
}

function setCompanyFindById(data) {
    $("#id").val(data.id);
    $("#name").val(data.name);
    $("#logoImg").val(data.logo);
    $("#content").val(data.content);
    $("#logoImg").attr("src", data.logo);
}

function saveCompanyData() {
    let data = new FormData();
    data.append("id", $("#id").val());
    data.append("name", $("#name").val());
    data.append("logo", $('#logo').get(0).files[0]);
    data.append("phone", $("#phone").val());
    data.append("content", $("#content").val());

    $.ajax({
        url: '/companyUpdate',
        data: data,
        type: 'post',
        contentType: false,
        processData: false,
        dataType: 'json',
        success: function (data) {
            $('#backright').load('/back/companySelect.jsp');
        }
    })
}